﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .buttonimg {
            background: url("../gq_moblie/images/button.png") no-repeat;
        }

            .buttonimg:hover {
                background: url("../gq_moblie/images/button_hover.png") no-repeat;
                background-size: 100%;
            }

        .buttonimg2 {
            background: url("../gq_moblie/images/button2.png") no-repeat;
        }
    </style>
</head>
<link rel="stylesheet" href="./css/style.css">
<script src="./js/flexible.min.js"></script>

<body>



    <div class="web_container">

        <div class="web_headerBlock">

            <div class="logo">
                <a href=""></a>
            </div>

            <div class="lie"></div>

            <div class="nav">
                <div class="lis"><a href="">White Paper</a></div>
                <div class="lis"><a href="">Contact</a></div>
                <div class="lis"><a href="">Discord</a></div>
                <div class="lis"><a href="">Telegram</a></div>
            </div>

            <div class="mesk"></div>

        </div>

        <div class="web_searchBlock">
            <div class="web_searchBlock_bar">
                <div class="left"><input id="ercAddress" type="text" placeholder="Enter Your Erc20 Wallet Address" /></div>
                <div class="right"><div id="submit" class="button buttonimg">Submit</div></div>
            </div>
        </div>


        <div class="web_posList">
            <div id="invitedNum" class="web_posList_conPost"></div>
            <div class="web_posList_tips">
                奖励说明<br />
                1.每日空投<span id="kongTouNum"></span>万个SAT 根据用户点击量分配。<br />
                2.每邀请一个新用户可获得该用户当日点击次数的1%奖励  邀请越多，奖励累计越多。
            </div>
        </div>

        <div class="web_posList_table">
            <table id="rewardList" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <th>日期</th>
                    <th>每日奖励</th>
                    <th>总点击量</th>
                </tr>
                <!--<tr>
                    <td>2019.1.10</td>
                    <td>200.00</td>
                    <td>876080.00</td>
                </tr>-->
            </table>
        </div>


        <div class="web_footer">2019 SmartX.inc</div>


    </div>


</body>
</html>
<script src="js/jquery-3.3.1.js"></script>
<script src="config.js"></script>
<script src="js/utils.js"></script>
<script src="js/comm.js"></script>
<script>
    

    let server = apiServer();
    let userid = "";
    let token = "";

    $(function () {
        pageInit();
        getInvitedInit();
        getRewardList();
        $("#submit").click(submit);
    });


    function getInvitedInit() {
        $.ajax({
            url: server + "/api/ShuiLongTou/GetInvited",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11",
                "Token": token,
            },
            success: function (data) {
                if (data && data.Code == 0) {
                    $("#invitedNum").text("已邀请人数" + data.Data.InvitedNum + "人");
                    $("#kongTouNum").text(data.Data.KontTouNum);
                }
                else {
                    $("#invitedNum").text("已邀请人数0人");
                    $("#kongTouNum").text("0");
                }
            }
        });
    }
   
    function getRewardList() {
        if (!userid || !token) {
            var html = '<tr>' +
                '<td style="text-align:left;" colspan="1">暂无数据，请先提交查看</td >'
            "</tr >";
            $("#rewardList").append(html);
            return false;
        }

        $.ajax({
            url: server + "/api/ShuiLongTou/GetRewardList",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11",
                "UserID": userid,
                "Token": token
            },
            success: function (data) {
                debugger
                if (data && data.Code == 0) {
                    if (!data.Data && data.Data.length <= 0) {
                        return;
                    }

                    var html = "";
                    for (var i = 0; i < data.Data.length; i++) {
                        html += "<tr>" +
                            "<td > " + data.Data[i].TouchTime + "</td >" +
                            "<td>" + data.Data[i].DailyReward + "</td>" +
                            "<td>" + data.Data[i].TouchCount + "</td>" +
                                "</tr >";
                    }
                    $("#rewardList").html("<tr>"+
                        "<th> 日期</th >" +
                        "<th>每日奖励</th>" +
                        "<th>总点击量</th>" +
                        "</tr >");
                    $("#rewardList").append(html);
                    pageInit();
                }
                else {
                    var html = '<tr>' +
                        '<td style="text-align:left;" colspan="1">暂无数据</td >'
                    "</tr >";
                    $("#rewardList").append(html);
                }
            }
        });
    }

    function setUrl(url) {
        var stateObject = {};
        var title = "Wow Title";
        var newUrl = url;
        history.pushState(stateObject, title, newUrl);
    }


    function submit() {
        debugger
        //userid = $("#userid").val();
        if (userid) {
            //alert("已经登陆");
            return false;
        }

        var ercAddress = $("#ercAddress").val();
        if (!ercAddress) {
            alert("请输入ERC地址");
            return false;
        }

        if (!checkErcForm(ercAddress)) {
            alert("请检查ERC地址格式是否正确");
            return false;
        }

        if (ercAddress.length > 80) {
            alert("请检查ERC地址格式是否正确");
            return false;
        }

        //erc格式不正确
        //if (ercAddress.length != 64) {
        //    return false;
        //}

        $.ajax({
            url: server + "/api/ShuiLongTou/CreateUserSLT",
            type: "POST",
            dataType: "json",
            data: {
                "Source": "11",
                "ERCAddress": ercAddress,
            },
            //error: function (XmlHttpRequest, textStatus, errorThrown) { alert(XmlHttpRequest.responseText); },
            success: function (data) {
                if (data && (data.Code == 0 || data.Code == 1)) {
                    token = data.Data.Token;
                    userid = data.Data.UserID;
                    $("#userNum").text(data.Data.UserCount);
                    $("#touchNum").text(data.Data.TouchCount);

                    //$("#userid").val(data.Data.UserID);
                    $("#submit").removeClass("buttonimg");
                    $("#submit").addClass("buttonimg2");
                    //不保存cookie,定位到url
                    var url = "list.html?userid=" + data.Data.UserID + "&token=" + data.Data.Token + "";
                    setUrl(url);

                    getRewardList();
                }
                else {
                    alert("提交失败，" + data.Msg);
                }
            }
        });
    }   

    $(window).resize(function () {
        if (document.body.clientWidth > 1000) {
            $('.nav').show();
        } else {
            $('.nav').hide();
            $('.mesk').hide();
        }
    })

    if (document.body.clientWidth > 1000) {
        $('.nav').show();
    } else {
        $('.nav').hide();
        $('.mesk').hide();
    }

    $('body').on('click', '.lie', function () {
        $('.nav').show();
        $('.mesk').show();
        $('body').css({ 'overflow-y': 'hidden' });
    })

    $('body').on('click', '.mesk', function () {
        $('.nav').hide();
        $('.mesk').hide();
        $('body').css({ 'overflow-y': '' });
    })

</script>
